package com.wish.renting.controller;

import com.wish.base.entity.SfTermination;
import com.wish.base.service.ISfTerminationService;
import com.wish.common.core.web.controller.BaseController;
import com.wish.common.core.web.page.TableDataInfo;
import com.wish.common.security.annotation.PreAuthorize;
import com.wish.renting.config.AjaxResult;
import com.wish.renting.config.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/*

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)

*/
@RestController
@RequestMapping("/termination")
public class TSfTerminationController extends BaseController {
    
    @Autowired
    private ISfTerminationService iSfTerminationService;

    @Autowired
    MsgUtil msgUtil;
    
    //查询列表
    @PreAuthorize(hasPermi = "renting:termination:list2")
    @GetMapping("/list")
    public TableDataInfo list(SfTermination sfTermination) {
        startPage();
        List<SfTermination> list = iSfTerminationService.list();
        return getDataTable(list);
    }


    //解约协议录入
    @PostMapping("addTermination")
    public AjaxResult addTermination(@RequestBody SfTermination sfTermination) {
        Calendar now = Calendar.getInstance();
        System.out.println("年: " + now.get(Calendar.YEAR));
        System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");
        System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));
        System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));
        System.out.println("分: " + now.get(Calendar.MINUTE));
        System.out.println("秒: " + now.get(Calendar.SECOND));
        System.out.println("当前时间毫秒数：" + now.getTimeInMillis());
        System.out.println(now.getTime());
        Date d = new Date();
        System.out.println(d);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateNowStr = sdf.format(d);
        System.out.println("格式化后的日期：" + dateNowStr);
        sfTermination.setSfTerminationNo("SFJY" + dateNowStr);
        msgUtil.sendTextEmail("937058265@qq.com", sfTermination.getOwnerName() + "解约成功",
                "解约编号:" + sfTermination.getSfTerminationNo()  + "\n解约时间:" + sfTermination.getWyjgDate());
        iSfTerminationService.saveOrUpdate(sfTermination);
        return AjaxResult.ok(sfTermination);
    }


    /*   *//**
 * 导出【请填写功能名称】列表
 *//*
    @PreAuthorize(hasPermi = "system:termination:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSfTermination tSfTermination) throws IOException
    {
        List<TSfTermination> list = tSfTerminationService.selectTSfTerminationList(tSfTermination);
        ExcelUtil<TSfTermination> util = new ExcelUtil<TSfTermination>(TSfTermination.class);
        util.exportExcel(response, list, "termination");
    }

    *//**
 * 获取【请填写功能名称】详细信息
 *//*
    @PreAuthorize(hasPermi = "system:termination:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tSfTerminationService.selectTSfTerminationById(id));
    }

    *//**
 * 新增【请填写功能名称】
 *//*
    @PreAuthorize(hasPermi = "system:termination:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSfTermination tSfTermination)
    {
        return toAjax(tSfTerminationService.insertTSfTermination(tSfTermination));
    }

    *//**
 * 修改【请填写功能名称】
 *//*
    @PreAuthorize(hasPermi = "system:termination:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSfTermination tSfTermination)
    {
        return toAjax(tSfTerminationService.updateTSfTermination(tSfTermination));
    }

    *//**
 * 删除【请填写功能名称】
 *//*
    @PreAuthorize(hasPermi = "system:termination:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSfTerminationService.deleteTSfTerminationByIds(ids));
    }*/
}

